package com.crack.nga2.volley;

import android.util.Log;

import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.crack.nga2.utils.GlobalConst;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * 更改子版块显示请求
 * Created by Administrator on 2016/1/6.
 */
public class ModifySubForumRequest extends Request<Void> {
    private Map<String, String> params;
    private Response.Listener<Void> listener;

    public ModifySubForumRequest(int method, String url, Map<String, String> params, Response.Listener<Void> listener, Response.ErrorListener errorListener) {
        super(method, url, errorListener);
        this.params = params;
        this.listener = listener;
    }

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> headFields = new HashMap<>();
        headFields.put("Cookie", GlobalConst.Cookie);
        return headFields;
    }

    @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        return params;
    }

    @Override
    protected Response<Void> parseNetworkResponse(NetworkResponse response) {
        try {
            Log.i("ModifyRe", new String(response.data, "GBK"));
            return Response.success(null, HttpHeaderParser.parseCacheHeaders(response));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return Response.error(new VolleyError(e.getMessage()));
        }
    }

    @Override
    protected void deliverResponse(Void response) {
        if (listener != null) {
            listener.onResponse(response);
        }
    }
}
